import baseURL from "@/common/url"
import axios from "axios";

const instance = axios.create({
  baseURL: baseURL.url, 
  timeout: 60000,
});

instance.interceptors.request.use(function (config) {
  config.headers.token = window.localStorage.getItem('admin_token')
  config.ContentType = "multipart/form-data"
  return config;
}, function (error) {
  return Promise.reject(error);
});

//get请求
export function get(url, data, headers = {}) {
  return new Promise((resolve, reject) => {
    instance.get(url, data, { headers }).then((response) => {
      resolve(response);
    }).catch((err) => {
      reject(err);
    });
  });
}

//post请求}
export function post(url, data = {}, headers = {}) {
  return new Promise((resolve, reject) => {
    instance.post(url, data, { headers }).then(
      (response) => {
        resolve(response);
      },
      (err) => {
        reject(err);
      }
    );
  });
}
